package com.zzgele.qmzb.api.web;

import com.alibaba.boot.dubbo.annotation.DubboConsumer;
import com.zzgele.qmzb.api.core.Result;
import com.zzgele.qmzb.api.core.ResultGenerator;
import com.zzgele.qmzb.api.model.Fans;
import com.zzgele.qmzb.api.model.User;
import com.zzgele.qmzb.api.service.FansService;
import com.zzgele.qmzb.api.service.UserService;
import com.zzgele.qmzb.api.utils.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created by Martin on 2017/07/09.
 */
@RestController
@RequestMapping("/temp")
public class TempController {
    private final Logger logger = LoggerFactory.getLogger(TempController.class);
    @DubboConsumer
    private UserService userService;
    @DubboConsumer
    private FansService fansService;

    @PostMapping("/user_info")
    public Result user_info(Long uid) {
        Integer currentUnixTimeStamp = DateUtil.getCurUnixTimeStampInt();
        Integer limitUnixTimeStamp = 1503158399; //2017-08-19 23:59:59
        if(currentUnixTimeStamp > limitUnixTimeStamp) {
            return ResultGenerator.genFailResult("临时接口失效");
        }

        User user = userService.findById(uid);
        HashMap hashMap = new HashMap();
        hashMap.put("nick_name", user.getNickName());
        hashMap.put("icon", user.getIcon());
        hashMap.put("gender", user.getGender());
        hashMap.put("number", user.getNumber());
        hashMap.put("sign", user.getSign());
        hashMap.put("diamond", user.getDiamond());

        //用户名片扩展字段所需要的
        hashMap.put("level", user.getLevel());
        hashMap.put("ticket", user.getTicketTotal());
        hashMap.put("spend", user.getSpend());

        int fans_count,follow_count;
        Fans fans;
        //我的粉丝=关注我的=(UID=我)
        fans = new Fans();
        fans.setUid(uid);
        fans_count = fansService.selectCount(fans);
        hashMap.put("fans_count", fans_count);
        //我的关注=我关注的=(FANS_UID=我)
        fans = new Fans();
        fans.setFansUid(uid);
        follow_count = fansService.selectCount(fans);
        hashMap.put("follow_count", follow_count);

        //修改个人信息需要的参数（登录时不需要）
        hashMap.put("authentication_status", user.getAuthenticationStatus());
        hashMap.put("province_id", user.getProvinceId());
        hashMap.put("city_id", user.getCityId());
        hashMap.put("birth", user.getBirth());
        hashMap.put("height", user.getHeight());
        hashMap.put("age", DateUtil.getAgeByBirth(user.getBirth()));

        return ResultGenerator.genSuccessResult(hashMap);
    }
}
